<template>
  <section class="page">
    <headerbar>
      贵阳组工信息
      <broadcastDetail v-if="typeof detail.newsContent !='undefined' && tools.NotIsNull(detail.newsContent.ttsOssUrl)" :detail="detail"/>
    </headerbar>

    <section class="bg-white" v-if="detail.title">
      <section class="detail">
        <h1 class="title">{{detail.title}}</h1>
        <p class="line"></p>
        <div class="cont-text" v-saveImage="saveImage" v-if="detail.content" v-html="detail.content"></div>

        <p class="pdv-2"></p>
        <viewsUpsComponent v-if="detail && isUpsComponent"></viewsUpsComponent>

      </section>
    </section>


    <div class="water-logo" v-if="!isComment">
      <img
        src="static/images/dangjian/home/water-logo-comment.png"
        alt=""
      />
      <div class="pdv-7"></div>
    </div>
    <section class="bg-white " :class="[{'d-scroll-2head': isComment},{'d-scroll-3head': isInputFocus}]">
      <!--<div class="water-logo" v-if="preData.comments < 1">
        <img src="../../../../static/images/dangjian/home/logo.png" alt="">
      </div>-->

      <commentListComponent v-if="detail.contentId && allowProhibit" :_contentId="detail.contentId" :shareType="7" :isUp="detail.isUp ==='1'? true : false" @onInputFocus="onInputFocus"></commentListComponent>
    </section>

    <!--<liveMsgComponent v-if="preData.id" :detail="preData" :contentId="preData.id" :comments="preData.comments"></liveMsgComponent>-->
    <readScore v-if="detail" :_contentId="detail.contentId" :type="1"></readScore>
  </section>
</template>

<script>
  import fileDownloadComponent from '@/components/common/fileDownloadComponent.vue'
  import commentListComponent from '@/components/common/commentListComponent'
  import viewsUpsComponent from '@/components/common/viewsUpsComponent'
  export default {
    components: {viewsUpsComponent, commentListComponent, fileDownloadComponent},
    name: 'groupInfoDetail',
    data () {
      return {
        preData: {},
        detail: {},
        shareDialogInstance: null,
        isComment:true,//是否允许评论 true 允许 false 不允许
        allowProhibit:true,//是否启用下方输入框 true 允许 false 不允许
        isUpsComponent:true,//是否展示点赞量和阅读量 true 展示 false 不展示,
        isInputFocus: false,
      }
    },
    created () {
      this.isComment = this.$route.params.isComment === false ? false : true
      this.isUpsComponent = this.$route.params.isUpsComponent === false ? false : true
      this.allowProhibit = this.$route.params.allowProhibit === false ? false : true
      this.loadData()
      this.$store.state.flagType = 1
    },
    methods: {
      onInputFocus(blo) {
        this.isInputFocus = blo;
      },
      showShareDialog () {
        if (!this.shareDialogInstance) {
          this.shareDialogInstance = this.$createShareDialog({
            $props: {
              newsId: this.$route.query.id || this.preData.id,
              newsTitle: this.preData.title,
              type: 0,
              listPic: this.detail.newsContent.listPic
            }
          })
        }
        this.shareDialogInstance.show()
      },
      saveImage (src) {
        this.$createActionSheet({
          title: '',
          active: 0,
          data: [
            {
              content: '保存图片'
            }
          ],
          onSelect: (item, index) => {
            console.log('onSelect', src)
            if (window.android && window.android.downloadFile) {
              window.android.downloadFile(src, `新闻图片${Date.now()}.png`)
            }
          }
        }).show()
      },
      loadData () {
        let id = this.$route.query.id
        this.fetchService.groupInfoContentInfo(id).then(res => {
          if (res.code === 0) {
            res.data.upOrDown = res.data.isUp == 1
            res.data.countComment = res.data.comments
            res.data.id = res.data.contentId
            this.detail = res.data
            this.$store.state.newsDetail = this.detail
            this.$store.state.newsDetail.detail = this.detail
            this.$store.state.newsDetail.detail.newsContent = this.detail
            this.preData = this.detail
            if (this.detail) {
              this.historyAdd()
            }
          }
        })
      },
    // 添加到我的足迹
      historyAdd () {
        let data = {
          contentId: this.detail.contentId,
          newsType: 0,  // 新闻类型(0图文;1长视频;2音频;3短视频)
        }
        this.fetchService.getgroupInfoContentInfoViews(data).then((res) => {
          if (res.code === 0) {
            this.detail.views++
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "@/common/stylus/moon.scss";
</style>
